package com._520it.crm.web.controller;

import com._520it.crm.domain.Permission;
import com._520it.crm.page.PageResult;
import com._520it.crm.service.IPermissionService;
import com._520it.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    IPermissionService permissionService;

    @RequestMapping("")
    public String index(){
       return "permission";
    }

    @RequestMapping("/reload")

    public AjaxResult reload(){
        AjaxResult result = null;
        try{
            result = new AjaxResult(true,"加载成功");
        }catch (Exception e){
            e.printStackTrace();
            result = new AjaxResult(false,"加载失败");
        }
        return result;
    }

    @RequestMapping("/queryAllPermission")
    @ResponseBody
    public PageResult queryAllPermission(){
        PageResult result = null;
        List<Permission> allPermission = permissionService.selectAll();
        result = new PageResult(allPermission.size(),allPermission);
        return result;
    }
    @RequestMapping("/queryPageResultByRoleId")
    @ResponseBody
    public PageResult queryPageResultByRoleId(Long roleId){
        PageResult result = null;
        List<Permission> selfPermission = permissionService.queryPageResultByRoleId(roleId);
        result = new PageResult(selfPermission.size(),selfPermission);
        return result;
    }
}
